package com.ruoyi.textbook.domain;

import com.ruoyi.common.utils.ObjectUtil;
import lombok.Data;

import java.util.Date;

@Data
public class Textbook {
    private Integer id;
    private String name;
    private String uri;
    private Integer type; // 0 文本 1视频
    private Integer categoryId; //分类ID
    private Integer subjectId; // 科目ID

    private Integer sort;

    private Date createTime;
    private Date updateTime;

    public void setDefault(){
        if(getType() == null && name != null){
            setTypeDefault();
        }
        if(getCategoryId() == null){
            setCategoryId(-1);
        }
        if(getSubjectId() == null){
            setSubjectId(-1);
        }
        if(getSort() == null){
            setSort(0);
        }
        createTime = new Date();
        updateTime = createTime;
    }

    public void setTypeDefault() {
        if(name.endsWith("mp4")){
            this.type = 1;
        }else {
            this.type = 0;
        }
    }

    /**
     * 检查考试信息是否完备
     */
    public void verifyComplete() {
        ObjectUtil.checkEmpty(name, "name");
        ObjectUtil.checkEmpty(uri, "uri");
        ObjectUtil.checkNull(type, "type");
    }
}
